package com.woniuxy.java102vuecli.controller;

import com.woniuxy.java102vuecli.entity.Menu;
import com.woniuxy.java102vuecli.service.MenuService;
import com.woniuxy.java102vuecli.util.JwtUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author author
 * @Create 2023-09-14 12:01
 */
@Slf4j
@RestController
@RequestMapping("/menu")
public class MenuController {

    @Autowired
    MenuService menuService;

    @RequestMapping("/get/all")
    public ResponseResult<List<Menu>> getAllMenus(){
        return new ResponseResult<List<Menu>>(200,"success",
                menuService.getAllMenus());
    }
    @RequestMapping("/remove/{mid}")
    public ResponseResult<Void> removeMenuByMid(@PathVariable("mid") int mid){
        menuService.removeMenuByMid(mid);
        return new ResponseResult<>(200,"success",null);
    }
    @RequestMapping("/getmuens")
    public ResponseResult<List<Menu>> getMenusByEid(@RequestHeader("token") String token){
       //根据token解析id
        int eid= Integer.parseInt(JwtUtil.getEid(token));
        //servie---mapper
        return new ResponseResult<List<Menu>>(200,"success",menuService.getMenusByEid(eid));
    }

}
